<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Vue basic</title>
    <script src="https://unpkg.com/vue@next"></script>
</head>

<body>
<div id="app">
    <div>{{plusCount}}</div>
</div>
<script>
    const useDebouncedRef = function (value, delay=20){
        let timeout
        return customRef((track, trigger)=>{
            return {
                get(){
                    track()
                    return value
                },
                set(newValue){
                  clearTimeout(timeout)
                  timeout=setTimeout(()=>{
                      value = newValue;
                      trigger()
                  }, delay)
                }
            }
        })
    }
    const { createApp, customRef} = Vue;
    const App = {
        setup() {

            return {
                text: useDebouncedRef("hello")
            }
        },
        template:`<input v-model="text"/>`
    }

    createApp(App).mount("#app")
</script>
</body>

</html>